package pl.us.ij.plugins.segmentation.forms;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import pl.us.ij.plugins.segmentation.infrastructure.CategoryInfo;
import pl.us.ij.plugins.segmentation.infrastructure.CommandParams;
import pl.us.ij.plugins.segmentation.localization.Localization;

import javax.swing.*;
import java.awt.*;
import java.util.ResourceBundle;

/**
 * Created by IntelliJ IDEA.
 * User: Przemek
 * Date: 2010-05-26
 * Time: 00:41:45
 * To change this template use File | Settings | File Templates.
 */
public class AboutForm extends CategoryInfo implements ICommandParamGather {
    private JPanel aboutPanel;
    private JTextPane imageJPluginCreatedAsTextPane;

    public AboutForm(IActionHandler actionHandler) {

//        usIconLabel.setIcon(new ImageIcon("plugins\\Segmentation\\us.gif"));
    }

    @Override
    public String getTitle() {
        return Localization.getString("aboutForm.title");
    }

    @Override
    public JPanel getPanel() {
        return aboutPanel;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getDescription() {
        return null;//Localization.getString("aboutForm.description");
    }

    @Override
    public CommandParams getCommandParams() {
        return new CommandParams();
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        aboutPanel = new JPanel();
        aboutPanel.setLayout(new FormLayout("fill:min(m;200px):grow", "center:max(d;4px):noGrow"));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new FormLayout("fill:m:grow", "center:d:noGrow,top:4dlu:noGrow,center:max(d;4px):noGrow,top:4dlu:noGrow,center:44px:grow,top:4dlu:noGrow,center:max(d;4px):noGrow,center:max(d;4px):noGrow"));
        CellConstraints cc = new CellConstraints();
        aboutPanel.add(panel1, cc.xy(1, 1, CellConstraints.DEFAULT, CellConstraints.TOP));
        final JLabel label1 = new JLabel();
        label1.setFont(new Font(label1.getFont().getName(), Font.BOLD, 20));
        label1.setForeground(new Color(-13421773));
        label1.setHorizontalAlignment(0);
        label1.setText("Segmentation ImageJ Plug-In");
        label1.setVerticalAlignment(1);
        label1.setVerticalTextPosition(1);
        label1.putClientProperty("html.disable", Boolean.FALSE);
        panel1.add(label1, cc.xy(1, 1, CellConstraints.DEFAULT, CellConstraints.TOP));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new FormLayout("fill:55px:noGrow,left:4dlu:noGrow,fill:max(d;4px):grow", "center:d:noGrow,top:4dlu:noGrow,center:max(d;4px):noGrow"));
        panel1.add(panel2, cc.xy(1, 8));
        final JLabel label2 = new JLabel();
        label2.setFont(new Font(label2.getFont().getName(), Font.BOLD, 12));
        this.$$$loadLabelText$$$(label2, ResourceBundle.getBundle("pl/us/ij/plugins/segmentation/localization/Localization").getString("aboutForm.version"));
        label2.setVerticalTextPosition(1);
        panel2.add(label2, cc.xy(1, 1, CellConstraints.LEFT, CellConstraints.DEFAULT));
        final JLabel label3 = new JLabel();
        label3.setFont(new Font(label3.getFont().getName(), Font.BOLD, 12));
        this.$$$loadLabelText$$$(label3, ResourceBundle.getBundle("pl/us/ij/plugins/segmentation/localization/Localization").getString("aboutForm.author"));
        label3.setVerticalTextPosition(1);
        panel2.add(label3, cc.xy(1, 3));
        final JLabel label4 = new JLabel();
        label4.setFont(new Font(label4.getFont().getName(), Font.ITALIC, 12));
        label4.setText("1.0");
        panel2.add(label4, cc.xy(3, 1));
        final JLabel label5 = new JLabel();
        label5.setFont(new Font(label5.getFont().getName(), Font.ITALIC, 12));
        label5.setText("Przemyslaw Gajdzik");
        panel2.add(label5, cc.xy(3, 3));
        final JLabel label6 = new JLabel();
        label6.setHorizontalAlignment(0);
        label6.setText("");
        panel1.add(label6, cc.xy(1, 7));
        final JLabel label7 = new JLabel();
        label7.setText("");
        panel1.add(label7, cc.xy(1, 3));
        imageJPluginCreatedAsTextPane = new JTextPane();
        imageJPluginCreatedAsTextPane.setBackground(UIManager.getColor("Label.background"));
        imageJPluginCreatedAsTextPane.setEditable(false);
        imageJPluginCreatedAsTextPane.setFont(new Font(imageJPluginCreatedAsTextPane.getFont().getName(), Font.ITALIC, 13));
        imageJPluginCreatedAsTextPane.setText(ResourceBundle.getBundle("pl/us/ij/plugins/segmentation/localization/Localization").getString("aboutForm.description"));
        imageJPluginCreatedAsTextPane.putClientProperty("JEditorPane.honorDisplayProperties", Boolean.FALSE);
        imageJPluginCreatedAsTextPane.putClientProperty("JEditorPane.w3cLengthUnits", Boolean.FALSE);
        panel1.add(imageJPluginCreatedAsTextPane, cc.xywh(1, 5, 1, 2, CellConstraints.FILL, CellConstraints.FILL));
    }

    /**
     * @noinspection ALL
     */
    private void $$$loadLabelText$$$(JLabel component, String text) {
        StringBuffer result = new StringBuffer();
        boolean haveMnemonic = false;
        char mnemonic = '\0';
        int mnemonicIndex = -1;
        for (int i = 0; i < text.length(); i++) {
            if (text.charAt(i) == '&') {
                i++;
                if (i == text.length()) break;
                if (!haveMnemonic && text.charAt(i) != '&') {
                    haveMnemonic = true;
                    mnemonic = text.charAt(i);
                    mnemonicIndex = result.length();
                }
            }
            result.append(text.charAt(i));
        }
        component.setText(result.toString());
        if (haveMnemonic) {
            component.setDisplayedMnemonic(mnemonic);
            component.setDisplayedMnemonicIndex(mnemonicIndex);
        }
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return aboutPanel;
    }
}
